//
//  SMBaseWindowViewCtrl.swift
//  SmartMachine
//
//  Created by Sherman's iMac on 2019/11/6.
//  Copyright © 2019 Smart. All rights reserved.
//

enum SMWindowType {
    case baseWindow
    case userWindow
    case basicConfigWindow
    case platFormWindow
}

import Cocoa

/// Base window controller
class SMBaseWindowViewCtrl: NSWindowController {
    
    override init(window: NSWindow?) {
        
        var win = window
        if win == nil {
            win = SMBaseWindow.init(contentRect: NSZeroRect, styleMask: [NSWindow.StyleMask.titled , NSWindow.StyleMask.closable, NSWindow.StyleMask.fullSizeContentView, NSWindow.StyleMask.texturedBackground], backing: NSWindow.BackingStoreType.buffered, defer: true)
        }
        super.init(window: win)
    } 
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func windowDidLoad() {
        super.windowDidLoad()
    }
}

/// base content window
class SMBaseWindow: NSWindow {
    
    public var windowType: SMWindowType?
    override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask, backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) {
        
        windowType = SMWindowType.baseWindow
        super.init(contentRect: contentRect, styleMask: style, backing: backingStoreType, defer: flag)
        let minBtn : NSButton? = self.standardWindowButton(NSWindow.ButtonType.miniaturizeButton)
        let maxBtn : NSButton? = self.standardWindowButton(NSWindow.ButtonType.zoomButton)
        minBtn?.isHidden = true
        maxBtn?.isHidden = true
        //self.backgroundColor = FUNC_COLOR(r: 47, g: 79, b: 79)
        self.backgroundColor = NSColor.white
        self.titlebarAppearsTransparent = false
    }
    
    override func close() {
        switch windowType {
        case .baseWindow:
            break 
        case .userWindow:
            AppDelegate.appDelegate()?.hideUseConfigCtrl()
        case .platFormWindow:
            AppDelegate.appDelegate()?.hidePlatFormConfigCtrl()
        case .basicConfigWindow:
            AppDelegate.appDelegate()?.hideBasicConfigCtrl()
        default: break
        }
        super.close()
    }
}
